-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(napi): Make napi_wrap work on regular objects #15622
base: main
Are you sure you want to change the base?
Conversation
src/bun.js/bindings/napi.cpp
Outdated
|
||
if (!refPtr) { | ||
return napi_object_expected; | ||
if (!hasNapiWrap(vm, globalObject, jsc_object)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This calls getDirect
twice. We only need to call it once. Let's call it once.
src/bun.js/bindings/napi.cpp
Outdated
} else if (auto* val = jsDynamicCast<NapiClass*>(value)) { | ||
ref = val->napiRef; | ||
|
||
if (!hasNapiWrap(vm, globalObject, jsc_object)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also calls getDirect twice
src/bun.js/bindings/napi.cpp
Outdated
} else { | ||
ASSERT(false); | ||
JSValue contents_value = jsc_object->getDirect(vm, propertyName); | ||
RETURN_IF_EXCEPTION(scope, napi_pending_exception); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to check for exceptions when using getDirect
What does this PR do?
Currently, napi_wrap only works on instances of Node-API classes. This PR will make it work on any JavaScript object.
Fixes #15383, which is occurring in
@napi-rs/canvas
and eventually in more projects because of napi-rs/napi-rs#2348How did you verify your code works?
Added tests and passes the existing ones.